package com.by.sbmpdemoby.web.controller;

import com.by.sbmpdemoby.pojo.Orders;
import com.by.sbmpdemoby.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * @auth wzy
 * @date 2023/12/16 9:37
 */

@Controller
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @GetMapping("/list")
    public String list(Model model){

        List<Orders> list = ordersService.list();
        model.addAttribute("list", list);

        return "orders/list";
    }

    @GetMapping("/{id}")
    public String getOrder(Model model, HttpServletRequest request, @PathVariable Integer id) {

        Orders order = ordersService.getById(id);
        model.addAttribute("order", order);

        request.setAttribute("test","request");
        request.getSession().setAttribute("test","session");
        model.addAttribute("date",new Date());


        return "orders/view";
    }
}
